package com.evil.activiti.api;

import com.evil.common.application.dto.process.*;
import com.evil.common.family.constant.ServiceNameConstant;
import com.evil.common.core.entity.PageModel;
import com.github.pagehelper.PageInfo;
import com.evil.activiti.config.ActivityFeignErrorDecoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import java.util.List;

@FeignClient(name = ServiceNameConstant.ACTIVITI_SERVICE, configuration = {ActivityFeignErrorDecoder.class})
public interface RemoteActivityService {

    /**
     * 部署流程
     *
     * @param processDeploymentReqDTO processDeploymentReqDTO
     * @return ProcessDeploymentRespDTO
     */
    @PostMapping("/remote/activiti/process/deployment")
    ProcessDeploymentRespDTO processDeployment(@Validated @RequestBody ProcessDeploymentReqDTO processDeploymentReqDTO);

    /**
     * 获取流程部署列表
     *
     * @param pageModel pageModel
     * @return List
     */
    @PostMapping("/remote/activiti/process/definitions")
    PageInfo<ProcessDefinitionRespDTO> getDefinitions(@Validated @RequestBody PageModel<Long> pageModel);

    /**
     * 获取列表实例列表
     *
     * @param pageModel pageModel
     * @return List
     */
    @PostMapping("/remote/activiti/process/instances")
    PageInfo<ProcessInstancesRespDTO> getInstances(@Validated @RequestBody PageModel<String> pageModel);

    /**
     * 创建实例
     *
     * @param processCreateTaskReqDTO processCreateTaskReqDTO
     * @return ProcessCreateTaskRespDTO
     */
    @PostMapping("/remote/activiti/task/create")
    ProcessCreateTaskRespDTO createTask(@Validated @RequestBody ProcessCreateTaskReqDTO processCreateTaskReqDTO);

    /**
     * 流转实例
     *
     * @param processCompleteTaskReqDTO processCompleteTaskReqDTO
     * @return ProcessCompleteTaskRespDTO
     */
    @PostMapping("/remote/activiti/task/complete")
    ProcessCompleteTaskRespDTO completeTask(@Validated @RequestBody ProcessCompleteTaskReqDTO processCompleteTaskReqDTO);

    /**
     * 流转撤回
     *
     * @param taskId taskId
     */
    @PostMapping("/remote/activiti/task/revoke")
    void revokeTask(@RequestParam("taskId") @NotBlank(message = "流程实例id不能为空") String taskId);

    /**
     * 重新指派
     *
     * @param processReassignmentTaskReqDTO processChangeTaskReqDTO
     */
    @PostMapping("/remote/activiti/task/reassignment")
    void reassignment(@Validated @RequestBody ProcessReassignmentTaskReqDTO processReassignmentTaskReqDTO);

    /**
     * 待办列表
     *
     * @param pageModel pageModel
     * @return List
     */
    @PostMapping("/remote/activiti/task/list")
    PageInfo<ProcessTaskRespDTO> findTaskByAssignee(@Validated @RequestBody PageModel<ProcessTaskReqDTO> pageModel);

    /**
     * 获取流程实例当前所在节点
     *
     * @param processInstanceId processInstanceId
     */
    @PostMapping("/remote/activiti/node/current")
    List<Long> getCurrentNodeByTaskId(@RequestParam("processInstanceId") @NotBlank(message = "流程实例id不能为空") String processInstanceId);

    /**
     * 获取流程可回退节点
     *
     * @param processTaskReqDTO processTaskReqDTO
     * @return List
     */
    @PostMapping("/remote/activiti/node/can-fallbacks")
    List<Long> getCanFallbacks(@Validated @RequestBody ProcessTaskReqDTO processTaskReqDTO);

    /**
     * 下载流程bpmn
     *
     * @param response response
     * @param id       id
     */
    @PostMapping("/remote/activiti/process/bpmn/down")
    void downBpmn(HttpServletResponse response, @RequestParam("id") @NotBlank(message = "不能为空") String id);
}
